<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class File extends MX_Controller {
    
  function __construct() {      
    
    $this->load->library('template');
    $this->load->library('form_eksternal');
    $this->load->library('global_models');
    $this->load->library('mypdf');
    $this->load->library('manimage');
    $this->load->library('PHPExcel');
    $this->load->library('encrypt');
    $this->load->helper('path');
    $this->load->helper('url');
    $this->load->helper('form');
    $this->load->helper('cookie');
    $this->load->library('parser');
    $this->load->library('session');
    $this->load->library('form_validation');
    $this->load->library('pagination');
    $this->load->library('email');
    $this->menu = $this->cek();
    
//    $this->debug($this->menu, true);
  }
	function download($id, $folder, $field = 'title'){
    $table = array(
        "mail"      => "d_mail_attachment",
        "spm"       => "sp2d_spm"
    );
    $where = array(
        "mail"      => "id_mail_attachment",
        "spm"       => "id_sp2d_spm"
    );
    $title = $this->global_models->get_field($table[$folder], $field, array($where[$folder] => $id));
    $file_ex = "./files/".$folder."/".$title;
    if(file_exists($file_ex)){
      header('Content-Description: File Transfer');
      header('Content-Type: application/octet-stream');
      header('Content-Disposition: attachment; filename='.basename($file_ex));
      header('Content-Transfer-Encoding: binary');
      header('Expires: 0');
      header('Cache-Control: must-revalidate');
      header('Pragma: public');
      header('Content-Length: ' . filesize($file_ex));
      ob_clean();
      flush();
      readfile($file_ex);
      exit;
    }
  }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */